package com.xiaotu.factory.factorymethod.pizzastore.order;


import com.xiaotu.factory.factorymethod.pizzastore.pizza.Pizza;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @author 张晓
 * @create 2020-06-19 10:25
 */
public abstract class OrderPizza {

    //定义一个抽象，createPizza ,让各个工厂子类自己实现
    abstract Pizza createPizza(String orderType);

    //构造器
    public OrderPizza(){
        Pizza pizza = null;
        String orderType = "";//用户输入
        do{
            orderType = getType();
            pizza = this.createPizza(orderType);
            //输出pizza
            if (pizza != null) {//订购成功
                pizza.prepare();
                pizza.bake();
                pizza.cut();
                pizza.box();
            }else {
                System.out.println(" 订购披萨失败 ");
                break;
            }
        }while (true);
    }

    //写一个方法，可以获取客户希望订购披萨的类型
    private String getType(){
        String str = null;
        BufferedReader br = null;
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
            System.out.println(" input pizza type: ");
            str = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
    }

}
